package com.ericom.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

@Entity
@Table(name="variation_type")
public class VariationType extends BaseObject {
	private Long id;
	private String name;
	private Set<VariationValue> values=new HashSet<VariationValue>();
	@OneToMany(mappedBy="variationType",cascade=CascadeType.ALL,fetch=FetchType.LAZY,targetEntity=VariationValue.class)
	public Set<VariationValue> getValues() {
		return values;
	}

	public void setValues(Set<VariationValue> values) {
		this.values = values;
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this).append("id", id)
				.append("name", name).toString();
	}

	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof VariationType))
			return false;
		VariationType castOther = (VariationType) other;
		return new EqualsBuilder().append(name, castOther.name).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(name).toHashCode();
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}



}
